/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import Model.ImageBean;
import Model.PropertyBean;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

/**
 *
 * @author amkreuz
 */
public class ImageDAO {

    private static Connection DBConn;

    public static void init() throws SQLException {
        try {
            Class.forName("org.apache.derby.jdbc.ClientDriver");
        } catch (ClassNotFoundException e) {
            System.err.println(e.getMessage());
            System.exit(0);
        }
        DBConn = DriverManager.getConnection("jdbc:derby://localhost:1527/FarmDB");
    }

    public static void terminate() throws SQLException {
        DBConn.close();
    }
    
    /**
     *
     * @return
     */
    public static ArrayList<ImageBean> getImageList(PropertyBean bean) throws SQLException {
        ArrayList<ImageBean> list = new ArrayList<>();
 
        Statement stmt = DBConn.createStatement();
        ResultSet rs = stmt.executeQuery("select * from image where address='"+bean.getAddress()+"' and zip="+bean.getZip());
        
        while (rs.next()) {
            ImageBean image = new ImageBean(rs.getString("filepath"));
            list.add(image);
        }
        
        return list;
    }
}
